home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / net / if.h < prev    next >
C/C++ Source or Header  |  1990-11-29  |  8KB  |  232 lines

  1. /*
  2.  * Copyright (c) 1982, 1986 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that this notice is preserved and that due credit is given
  7.  * to the University of California at Berkeley. The name of the University
  8.  * may not be used to endorse or promote products derived from this
  9.  * software without specific prior written permission. This software
  10.  * is provided ``as is'' without express or implied warranty.
  11.  *
  12.  *    @(#)if.h    7.2 (Berkeley) 12/30/87
  13.  */
  14.  
  15. #ifndef _IF
  16. #define _IF
  17.  
  18. /*
  19.  * Structures defining a network interface, providing a packet
  20.  * transport mechanism (ala level 0 of the PUP protocols).
  21.  *
  22.  * Each interface accepts output datagrams of a specified maximum
  23.  * length, and provides higher level routines with input datagrams
  24.  * received from its medium.
  25.  *
  26.  * Output occurs when the routine if_output is called, with three parameters:
  27.  *    (*ifp->if_output)(ifp, m, dst)
  28.  * Here m is the mbuf chain to be sent and dst is the destination address.
  29.  * The output routine encapsulates the supplied datagram if necessary,
  30.  * and then transmits it on its medium.
  31.  *
  32.  * On input, each interface unwraps the data received by it, and either
  33.  * places it on the input queue of a internetwork datagram routine
  34.  * and posts the associated software interrupt, or passes the datagram to a raw
  35.  * packet input routine.
  36.  *
  37.  * Routines exist for locating interfaces by their addresses
  38.  * or for locating a interface on a certain network, as well as more general
  39.  * routing and gateway routines maintaining information used to locate
  40.  * interfaces.  These routines live in the files if.c and route.c
  41.  */
  42.  
  43. /*
  44.  * Structure defining a queue for a network interface.
  45.  *
  46.  * (Would like to call this struct ``if'', but C isn't PL/1.)
  47.  */
  48. struct ifnet {
  49.     char    *if_name;        /* name, e.g. ``en'' or ``lo'' */
  50.     short    if_unit;        /* sub-unit for lower level driver */
  51.     short    if_mtu;            /* maximum transmission unit */
  52.     short    if_flags;        /* up/down, broadcast, etc. */
  53.     short    if_timer;        /* time 'til if_watchdog called */
  54.     int    if_metric;        /* routing metric (external only) */
  55.     struct    ifaddr *if_addrlist;    /* linked list of addresses per if */
  56.     struct    ifqueue {
  57.         struct    mbuf *ifq_head;
  58.         struct    mbuf *ifq_tail;
  59.         int    ifq_len;
  60.         int    ifq_maxlen;
  61.         int    ifq_drops;
  62.     } if_snd;            /* output queue */
  63. /* procedure handles */
  64.     int    (*if_init)();        /* init routine */
  65.     int    (*if_output)();        /* output routine */
  66.     int    (*if_ioctl)();        /* ioctl routine */
  67.     int    (*if_reset)();        /* bus reset routine */
  68.     int    (*if_watchdog)();    /* timer routine */
  69. /* generic interface statistics */
  70.     int    if_ipackets;        /* packets received on interface */
  71.     int    if_ierrors;        /* input errors on interface */
  72.     int    if_opackets;        /* packets sent on interface */
  73.     int    if_oerrors;        /* output errors on interface */
  74.     int    if_collisions;        /* collisions on csma interfaces */
  75. /* end statistics */
  76.     struct    ifnet *if_next;
  77. };
  78.  
  79. #define    IFF_UP        0x1        /* interface is up */
  80. #define    IFF_BROADCAST    0x2        /* broadcast address valid */
  81. #define    IFF_DEBUG    0x4        /* turn on debugging */
  82. #define    IFF_LOOPBACK    0x8        /* is a loopback net */
  83. #define    IFF_POINTOPOINT    0x10        /* interface is point-to-point link */
  84. #define    IFF_NOTRAILERS    0x20        /* avoid use of trailers */
  85. #define    IFF_RUNNING    0x40        /* resources allocated */
  86. #define    IFF_NOARP    0x80        /* no address resolution protocol */
  87. /* next two not supported now, but reserved: */
  88. #define    IFF_PROMISC    0x100        /* receive all packets */
  89. #define    IFF_ALLMULTI    0x200        /* receive all multicast packets */
  90. /* flags set internally only: */
  91. #define    IFF_CANTCHANGE    (IFF_BROADCAST | IFF_POINTOPOINT | IFF_RUNNING)
  92.  
  93. /*
  94.  * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
  95.  * input routines have queues of messages stored on ifqueue structures
  96.  * (defined above).  Entries are added to and deleted from these structures
  97.  * by these macros, which should be called with ipl raised to splimp().
  98.  */
  99. #define    IF_QFULL(ifq)        ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
  100. #define    IF_DROP(ifq)        ((ifq)->ifq_drops++)
  101. #define    IF_ENQUEUE(ifq, m) { \
  102.     (m)->m_act = 0; \
  103.     if ((ifq)->ifq_tail == 0) \
  104.         (ifq)->ifq_head = m; \
  105.     else \
  106.         (ifq)->ifq_tail->m_act = m; \
  107.     (ifq)->ifq_tail = m; \
  108.     (ifq)->ifq_len++; \
  109. }
  110. #define    IF_PREPEND(ifq, m) { \
  111.     (m)->m_act = (ifq)->ifq_head; \
  112.     if ((ifq)->ifq_tail == 0) \
  113.         (ifq)->ifq_tail = (m); \
  114.     (ifq)->ifq_head = (m); \
  115.     (ifq)->ifq_len++; \
  116. }
  117. /*
  118.  * Packets destined for level-1 protocol input routines
  119.  * have a pointer to the receiving interface prepended to the data.
  120.  * IF_DEQUEUEIF extracts and returns this pointer when dequeueing the packet.
  121.  * IF_ADJ should be used otherwise to adjust for its presence.
  122.  */
  123. #define    IF_ADJ(m) { \
  124.     (m)->m_off += sizeof(struct ifnet *); \
  125.     (m)->m_len -= sizeof(struct ifnet *); \
  126.     if ((m)->m_len == 0) { \
  127.         struct mbuf *n; \
  128.         MFREE((m), n); \
  129.         (m) = n; \
  130.     } \
  131. }
  132. #define    IF_DEQUEUEIF(ifq, m, ifp) { \
  133.     (m) = (ifq)->ifq_head; \
  134.     if (m) { \
  135.         if (((ifq)->ifq_head = (m)->m_act) == 0) \
  136.             (ifq)->ifq_tail = 0; \
  137.         (m)->m_act = 0; \
  138.         (ifq)->ifq_len--; \
  139.         (ifp) = *(mtod((m), struct ifnet **)); \
  140.         IF_ADJ(m); \
  141.     } \
  142. }
  143. #define    IF_DEQUEUE(ifq, m) { \
  144.     (m) = (ifq)->ifq_head; \
  145.     if (m) { \
  146.         if (((ifq)->ifq_head = (m)->m_act) == 0) \
  147.             (ifq)->ifq_tail = 0; \
  148.         (m)->m_act = 0; \
  149.         (ifq)->ifq_len--; \
  150.     } \
  151. }
  152.  
  153. #define    IFQ_MAXLEN    50
  154. #define    IFNET_SLOWHZ    1        /* granularity is 1 second */
  155.  
  156. /*
  157.  * The ifaddr structure contains information about one address
  158.  * of an interface.  They are maintained by the different address families,
  159.  * are allocated and attached when an address is set, and are linked
  160.  * together so all addresses for an interface can be located.
  161.  */
  162. struct ifaddr {
  163.     struct    sockaddr ifa_addr;    /* address of interface */
  164.     union {
  165.         struct    sockaddr ifu_broadaddr;
  166.         struct    sockaddr ifu_dstaddr;
  167.     } ifa_ifu;
  168. #define    ifa_broadaddr    ifa_ifu.ifu_broadaddr    /* broadcast address */
  169. #define    ifa_dstaddr    ifa_ifu.ifu_dstaddr    /* other end of p-to-p link */
  170.     struct    ifnet *ifa_ifp;        /* back-pointer to interface */
  171.     struct    ifaddr *ifa_next;    /* next address for interface */
  172. };
  173.  
  174. /*
  175.  * Interface request structure used for socket
  176.  * ioctl's.  All interface ioctl's must have parameter
  177.  * definitions which begin with ifr_name.  The
  178.  * remainder may be interface specific.
  179.  */
  180. struct    ifreq {
  181. #define    IFNAMSIZ    16
  182.     char    ifr_name[IFNAMSIZ];        /* if name, e.g. "en0" */
  183.     union {
  184.         struct    sockaddr ifru_addr;
  185.         struct    sockaddr ifru_dstaddr;
  186.         struct    sockaddr ifru_broadaddr;
  187.         short    ifru_flags;
  188.         int    ifru_metric;
  189.         caddr_t    ifru_data;
  190.     } ifr_ifru;
  191. #define    ifr_addr    ifr_ifru.ifru_addr    /* address */
  192. #define    ifr_dstaddr    ifr_ifru.ifru_dstaddr    /* other end of p-to-p link */
  193. #define    ifr_broadaddr    ifr_ifru.ifru_broadaddr    /* broadcast address */
  194. #define    ifr_flags    ifr_ifru.ifru_flags    /* flags */
  195. #define    ifr_metric    ifr_ifru.ifru_metric    /* metric */
  196. #define    ifr_data    ifr_ifru.ifru_data    /* for use by interface */
  197. };
  198.  
  199. struct ifdevea {
  200.         char    ifr_name[IFNAMSIZ];
  201.         u_char default_pa[6];
  202.         u_char current_pa[6];
  203. }; 
  204.  
  205. /*
  206.  * Structure used in SIOCGIFCONF request.
  207.  * Used to retrieve interface configuration
  208.  * for machine (useful for programs which
  209.  * must know all networks accessible).
  210.  */
  211. struct    ifconf {
  212.     int    ifc_len;        /* size of associated buffer */
  213.     union {
  214.         caddr_t    ifcu_buf;
  215.         struct    ifreq *ifcu_req;
  216.     } ifc_ifcu;
  217. #define    ifc_buf    ifc_ifcu.ifcu_buf    /* buffer address */
  218. #define    ifc_req    ifc_ifcu.ifcu_req    /* array of structures returned */
  219. };
  220.  
  221. #ifdef KERNEL
  222. #include "../net/if_arp.h"
  223. struct    ifqueue rawintrq;        /* raw packet input queue */
  224. struct    ifnet *ifnet;
  225. struct    ifaddr *ifa_ifwithaddr(), *ifa_ifwithnet();
  226. struct    ifaddr *ifa_ifwithdstaddr();
  227. #else KERNEL
  228. #include <net/if_arp.h>
  229. #endif KERNEL
  230.  
  231. #endif _IF
  232.